<script src="../manager/js/jquery-3.5.0.js"></script>
<script src="../manager/layer/layer.js"></script>
<!-- <script src="../validation/lib/jquery.js"></script> -->
<script src="../validation/dist/jquery.validate.min.js"></script>
<script src="../validation/dist/localization/messages_zh.js"></script>
<script>
$(function(){
	function clear(){
		$("#oldpwd").val("");
		$("#newpwd").val("");
		$("#cfmpwd").val("");
	}
	$("#cancel").click(function(){
		clear();
	})
	$("#updatepwd").click(function(){
		let oldpwd = $("#oldpwd").val();
		let newpwd = $("#newpwd").val();
		let repwd = $("#cfmpwd").val();
		let data = {
			"opr":"updatePwd",
			"oldpwd":oldpwd,
			"newpwd":newpwd,
			"repwd":repwd
		}
		$.getJSON("../user",data,function(result){
			if(result.code==200){
				layer.alert("密码更新成功,请重新登陆!");
				setTimeout(function(){
					location.href="../login.jsp"
				},"3000")
			}else{
				layer.alert("密码更新失败："+result.msg)
			}
		})
	})
	console.log("come in");
	$().ready(function(){
		$("#pwdupdate").validate({
			rules:{
				oldpwd:{
					required:true,
					remote:{
						url:"../user?opr=checkPwd",
						type:"post",
						dataType:"json",
						data:{
							pwd:function(){
								return $("#oldpwd").val();
							}
						}
					}
				},
			
				newpwd:{
					required:true,
					minlength:6,
					maxlength:32,
				},
				repwd:{
					equalTo:"#newpwd"
				}
			},
			messages:{
				oldpwd:{
					required:"原密码不能为空",
					remote:"密码错误"
				},
				newpwd:{
					required:"密码不能为空",
					minlength:"密码长度不能小于6位",
					maxlength:"密码长度不能大于32位",
				},
				repwd:{
					equalTo:"更改后密码不一致"
				}
			}
		})
	})
})
</script>
<div class='tabs'>
	<div class="uc_title m_10 tabs_menu">
		<label class="current node"><span>修改密码</span></label>
	</div>
</div>
<form id="pwdupdate">
<table class="form_table" width="100%" cellpadding="0" cellspacing="0">
	<col width="120px" />
	<col />
	<tr>
		<th>原密码：</th>
		<td><input id='oldpwd' class="normal" name="oldpwd" type="password" /><label></label></td>
	</tr>
	<tr>
		<th>新密码：</th>
		<td><input id='newpwd' class="normal" name='newpwd' type="password" /><label></label></td>
	</tr>
	<tr>
		<th>确认密码：</th>
		<td><input id='cfmpwd' class="normal" name='repwd' type="password" /><label></label></td>
	</tr>
	<tr>
		<th></th>
		<td><label class="btn"><input type="button" id="updatepwd"
				value="保存" /></label> <label class="btn"><input type="button"
				id="cancel" value="取消" /></label></td>
	</tr>
</table>
</form>>
